<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/1/9-14:37
// +----------------------------------------------------------------------
// | Description:  
// +---------------------------------------------------------------------- 
*-->
{extend name="public/base" /}


{block name='content'}

<div class="layui-col-md12">


    <div class="layui-card">
        <div class="layui-card-header" >
                <a  href="{:url('admin/databack/index')}" class="layui-btn layui-btn-sm layui-btn-primary">返回</a>
        </div>
        <div class="layui-card-body">

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">


                        <div class="layui-form" style="margin:20px 0;">
                            <table class="layui-table"  lay-even="" lay-skin="row" lay-size="">
                                <colgroup>
                                    <col width="50">
                                    <col width="150">
                                    <col width="150">
                                    <col width="150">
                                    <col width="200">
                                    <col width="200">
                                    <col width="100">
                                </colgroup>
                                <thead>
                                <tr>

                                    <th>备份名称</th>
                                    <th>卷数</th>
                                    <th>压缩</th>
                                    <th>数据大小</th>
                                    <th>备份时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>



                                <tbody>
                                {foreach name='list' item='data'}
                                <tr>

                                    <td>{$data.time|date='Y-m-d H:i:s'}</td>
                                    <td>{$data.part}</td>
                                    <td>{$data.compress}</td>
                                    <td>{$data.size|formBytes}</td>
                                    <td>{$key}</td>
                                    <td class="status">-</td>
                                    <td class="action">
                                        <a class="layui-btn layui-btn-xs db-import" href="{:url('admin/databack/import',['time'=>$data['time']])}">还原</a>&nbsp;
                                        <a class="layui-btn layui-btn-xs ajax-get confirm delete" href="javascript:;" time="{$data.time}">删除</a>
                                    </td>
                                </tr>
                                {/foreach}
                                </tbody>


                            </table>

                        </div>


                    </div>
                </div>
            </div>

        </div>
    </div>

</div>


{/block}


{block name="js"}


<script>
    layui.use(['jquery','layer'],function(){
        window.$ = layui.$;
        var layer = layui.layer;

        /**
         * 备份卷还原
         */
        $(".db-import").click(function(){
            var self = this, status = ".";
            $(this).parent().prevAll('.status').html("").html('等待还原');
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;

            function success(data){
                if(data.code==1){
                    $(self).parent().prev().text(data.msg);

                    if(data.data.part){
                        $.get(self.href,
                            {"part" : data.data.part, "start" : data.data.start},
                            success,
                            "json"
                        );
                    }  else {
                        layer.alert(data.msg);
                    }
                } else {
                    layer.alert(data.msg);
                }
            }
        });


        /**
         * 删除备份卷
         */
        $('.delete').click(function(){
            var time = $(this).attr('time');
            $.ajax({
                url:"{:url('admin/databack/del')}"
                ,data:{time:time}
                ,success:function(res){
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = res.url;
                        },1500)
                    }
                }
            })
        });

    });

</script>

{/block}